package com.xhj.bigfactory.bigFactory.Lock;
/**
 * -
 *
 * @author icpick @Date 2021-07-25 @Time 23:42
 */
public class SyncDemo {
  public static void main(String[] args) {
    DataSD data = new DataSD();
    new Thread(
            () -> {
              System.out.println(Thread.currentThread().getName() + " come in...");
              data.addPlusPlus();
            },
            "AAA")
        .start();
    for (int i = 0; i < 4; i++) {
      new Thread(
              () -> {
                System.out.println(Thread.currentThread().getName() + " come in...");
                data.addPlusPlus();
              },
              "t" + i)
          .start();
    }
    //    while(Thread.activeCount()>2){Thread.yield();}
    System.out.println("data.number = " + data.number);
  }
}

class DataSD {
  int number = 0; // - - - - - 多线程不可见

  public synchronized void addPlusPlus() {
    System.out.println("add.....");
    number++;
    dec();
  }

  private synchronized void dec() {
    System.out.println("dec....");
  }
}
